home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
pas2c.zip
/
PASOBJ.C
< prev
next >
Wrap
Text File
|
1993-01-04
|
8KB
|
250 lines
/*
PASOBJ.C
Convert OBJ file for use with Turbo Pascal V4.0
The idea is to catch the LNAMES directive in the OBJ file, and
translate it. BSS, CODE and DATA are class names, and are cleared.
_TEXT, _DATA and _BSS are segment names, and are converted to
CSEG, CONST and DSEG respectively. DGROUP is the name of the DATA
group, and is cleared. All other records are copied verbatim.
All Identifiers in PUBLIC and EXTERNAL declarations are checked to
see if they have an '@' sign in the name. If an '@' sign is found,
the '@' is converted to an underscore '_'. This is to allow C
intrinsic functions to be used.
If a segment identifier matches the name xxx_TEXT, then it is
converted to CSEG. Note that this happens when Turbo C Large Model
code is being imported. Specifically, for "shared" library code.
Remember that any procedures brought in this way MUST be declared
with {$F+} switch.
Compile with Turbo C, small model, no floating point.
*/
#include <std.h>
#include <conio.h>
#include <dos.h>
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
LOCAL COUNT chksum;
LOCAL FILE *Inf, *Outf;
LOCAL COUNT Chr, Siz;
LOCAL VOID poll(VOID)
{
if (bdos(6, 255, 0) == 3)
exit(7);
}
LOCAL COUNT getch(VOID) /* get byte from Inf, polling */
{
poll();
--Siz;
return (getc(Inf));
}
LOCAL COUNT getwd(VOID) /* get word from Inf, polling */
{
poll();
Siz -= 2;
return (getw(Inf));
}
LOCAL TEXT *donam(VOID) /* copy name from record */
{
COUNT n;
TEXT *t, *t1;
n = getch(); /* number of chars in name */
t1 = t = malloc(n + 1); /* get space for it */
while (n--)
{
*t++ = getch(); /* save the name for use */
}
*t = 0;
return (t1);
}
LOCAL VOID outbyte(TEXT c)
{
c &= 0xFF;
chksum += c;
putc(c, Outf);
}
LOCAL VOID outstring(TEXT *s)
{
COUNT n;
n = strlen(s);
outbyte(n);
while (n--)
outbyte(*s++);
}
LOCAL VOID dofile(VOID)
{
TEXT *s, *t;
COUNT newsize, nstrings, i;
TEXT *strings[100];
COUNT si, gi;
while ((Chr = getch()) != EOF)
{
if (Chr && (Siz = getwd()) > 0) /* skip over null fill */
{
switch (Chr)
{
case 0x96: /* LNAMES */
newsize = 1;
nstrings = 0;
while (Siz > 1)
{
s = donam();
if (strcmp(s, "CODE") == 0)
s = "";
if (strcmp(s, "DATA") == 0)
s = "";
if (strcmp(s, "BSS") == 0)
s = "";
if (strcmp(s, "_TEXT") == 0)
s = "CSEG";
if (strcmp(s, "_DATA") == 0)
s = "CONST";
if (strcmp(s, "_BSS") == 0)
s = "DSEG";
if (strcmp(s, "DGROUP") == 0)
s = "";
if ((strlen(s) > 5) &&
(strcmp(s + strlen(s) - 5, "_TEXT") == 0))
s = "CSEG";
newsize += strlen(s) + 1;
strings[nstrings++] = s;
}
getch(); /* skip the original checksum byte */
chksum = 0;
outbyte(Chr);
outbyte(newsize & 0xFF);
outbyte((newsize >> 8) & 0xFF);
for (i = 0; i < nstrings; ++i)
outstring(strings[i]);
chksum = -chksum;
outbyte(chksum & 0xFF);
continue;
case 0x8C: /* EXTDEF */
chksum = 0;
outbyte(Chr);
outbyte(Siz & 0xFF);
outbyte((Siz >> 8) & 0xFF);
while (Siz > 1)
{
s = donam();
for (t = s; *t; ++t)
if (*t == '@')
*t = '_';
outstring(s);
outbyte(getch());
}
getch(); /* skip the original checksum byte */
chksum = -chksum;
outbyte(chksum & 0xFF);
continue;
case 0x90: /* PUBDEF */
chksum = 0;
outbyte(Chr);
outbyte(Siz & 0xFF);
outbyte((Siz >> 8) & 0xFF);
outbyte(si = getch());
outbyte(gi = getch());
if (si | gi)
;
else
{
outbyte(getch());
outbyte(getch());
}
while (Siz > 1)
{
s = donam();
for (t = s; *t; ++t)
if (*t == '@')
*t = '_';
outstring(s);
outbyte(getch());
outbyte(getch());
outbyte(getch());
}
getch(); /* skip the original checksum byte */
chksum = -chksum;
outbyte(chksum & 0xFF);
continue;
}
outbyte(Chr);
outbyte(Siz & 0xFF);
outbyte((Siz >> 8) & 0xFF);
while (Siz)
outbyte(getch());
}
}
}
VOID main (COUNT argc, TEXT *argv[])
{
TEXT *inname;
printf("PASOBJ 1.00A " __DATE__ "\n"
"Written by Martin Weigel 76237,733\n"
if (argc < 2 || argc > 3)
{
printf("\nusage: pasobj <infile> [<outfile>]\n\n"
"PASOBJ converts an OBJ file produced by Turbo C, Compact Model,\n"
"into an OBJ file suitable for inclusion into a Turbo Pascal 4.0\n"
"program via the $L directive. The .OBJ extension must be used on\n"
"both the input and output files. If the outfile is not specified,\n"
"the infile will be converted to a file of the same name.\n\n");
exit(1);
}
inname = * ++argv;
if ((Inf = fopen(inname, "rb")) == NIL)
{
printf("file <%s> could not be opened\n", *argv);
exit(1);
}
if (argc == 3)
{
if ((Outf = fopen(* ++argv, "wb")) == NIL)
{
printf("file <%s> could not be created\n", *argv);
exit(1);
}
}
else
{
if ((Outf = fopen("PO$$$.$$$", "wb")) == NIL)
{
printf("could not create temporary file\n");
exit(1);
}
}
dofile();
fclose(Inf);
fclose(Outf);
if (argc == 2)
{
unlink(inname);
rename("PO$$$.$$$", inname);
}
exit(0);
}